package cn.binarywang.tools.generator;
/**
 * @Title: WriteFile.java
 * @author liuf
 * @date 2020年11月10日 上午9:41:59
 * @version V1.0
 */


import cn.binarywang.tools.generator.bank.BankCardNumberGenerator;
import cn.binarywang.tools.generator.event.CarEventTypeEnum;
import org.testng.annotations.Test;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;

public class WriteFile {
    @Test
    public  void TestData() {
      Integer count =1;
//        for (int x = 0; x <10 ; x++) {
//            String  FileName = +count+"_"+ChineseIDCardNumberGenerator.getDate()+"_"+x;
////       String data = "/Users/liuf/Documents/work space/java-generator/java-generator/shell/";
//            for (int i = 0; i <10 ; i++) {
//                evnet(FileName,1000000);
//            }
//        }

            String  FileName = +count+"_"+ ChineseIDCardNumberGenerator.getDate()+"_"+count;
//       String data = "/Users/liuf/Documents/work space/java-generator/java-generator/shell/";

         evnet(FileName,count);

    }

    public static void evnet(String FileName ,Integer count) {
        try {
            StringBuffer sb =  new  StringBuffer();

            StringBuffer eventsb =  new  StringBuffer();
            String appid = "";
            // sb.append("sn,name,email,mobile,city,data");
            //sb.append("\r\n");

            for (int i = 0; i <count; i++) {
                // 姓名
                String name = ChineseNameGenerator.getInstance().generate();
                if (i%2 == 0) {
                    name = ChineseNameGenerator.getInstance().generate();
                } else {
                    name = ChineseNameGenerator.getInstance().generateOdd();
                }
                // 随机id
                String idCard = ChineseIDCardNumberGenerator.getInstance().generate();
                // 银行卡号
                String bankCardNo = BankCardNumberGenerator.getInstance().generate();

                String email = EmailAddressGenerator.getInstance().generate();

                String mobile = ChineseMobileNumberGenerator.getInstance().generateFake();
                // 车牌号
                String CarNo = CarNoGenerator.getInstance().generate();

                String carBrand = CarBrandGenerator.getInstance().generate();
                // 家庭住址
                String address = ChineseAddressGenerator.getInstance().generate();
                // 随机日期
                String randomDate = ChineseIDCardNumberGenerator.getRandDateTime();
//                String genProvinceAndCity = ChineseAddressGenerator.genProvinceAndCity();
                // 城市
                String genCity = ChineseAddressGenerator.genCity();
                CarEventTypeEnum carEvent = CarEventGenerator.getCarEvent();

                String str =idCard+","+name+","+email+","+mobile+","+genCity+","+CarNo+","+carBrand+","+i+","+ ChineseIDCardNumberGenerator.getRandDateTime()+","+ ChineseIDCardNumberGenerator.getRandDateTime()+","+ ChineseIDCardNumberGenerator.getRandDateTime()+","+ ChineseIDCardNumberGenerator.getRandDateTime();
                sb.append(str);
                sb.append("\r\n");
//                EventTypeEnum eventType = EventTypeEnum.getCode(i%EventTypeEnum.values().length);
                String eventStr1 = ChineseIDCardNumberGenerator.getInstance().generate()+","+idCard+","+carEvent.getCode()+","+carEvent.getText()+","+ ChineseIDCardNumberGenerator.getRandDateTime()+","+ ChineseIDCardNumberGenerator.getRandDateTime();
                String eventStr2 = ChineseIDCardNumberGenerator.getInstance().generate()+","+idCard+","+carEvent.getCode()+","+carEvent.getText()+","+ ChineseIDCardNumberGenerator.getRandDateTime()+","+ ChineseIDCardNumberGenerator.getRandDateTime();
                eventsb.append(eventStr1);
                eventsb.append("\r\n");
                eventsb.append(eventStr2);
                eventsb.append("\r\n");
            }
            // 用户
            File file = new File("user_"+FileName);
            if (!file.exists()) {
                file.createNewFile();
            }
            FileWriter fileWritter = new FileWriter(file.getName(), true);
            BufferedWriter bufferWritter = new BufferedWriter(fileWritter);
            bufferWritter.write(sb.toString());
            bufferWritter.close();

            // 事件
            File eventFile = new File("event_"+FileName);
            if (!eventFile.exists()) {
                eventFile.createNewFile();
            }
            FileWriter eventfileWritter = null;
            eventfileWritter = new FileWriter(eventFile.getName(), true);
            BufferedWriter eventbufferWritter = new BufferedWriter(eventfileWritter);
            eventbufferWritter.write(eventsb.toString());
            eventbufferWritter.close();

            System.out.println("Done");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }






}
